<template>
    <ynet-content id="requestPin" :headerInformation="true" :headerMenu="true" class="main-container">
        <div ><!--提示当前位置  电话银行交易查询-->
			<ynet-breadcrumb></ynet-breadcrumb>
		</div>
        <div  v-if="main">
            <div>
                <el-form ref="queryForm" :model="queryForm" class="formEmbedTable mt20" :rules="rules">
                    <table>
                        <caption>Enquiry</caption>
                        <tr>
                            <td> Primary A/C No.</td>
                            <td colspan='3'>
                                <el-form-item prop="accNo">
                                    <el-input v-model="queryForm.accNo"></el-input>
                                </el-form-item>
                            </td>					
                        </tr>
                    </table>
                </el-form>
            </div>
            <div class="btnArea mt20 tac">
                <el-button type="primary" @click="query('queryForm')">Search</el-button>
            </div>
            
        </div>
        <div v-if="submitForm.accStt!=2 && submitForm.accStt!=''">
            <el-form ref="queryForm" :model="queryForm" class="formEmbedTable mt20" :rules="rules">
                <table>
                    <caption>Result</caption>
                    <tr>
                        <td> TBS A/C STATUS: </td>
                        <td>
                            <el-form-item prop="accStt">{{$tools.dict.accStatus(submitForm.accStt)}}</el-form-item>
                        </td>	
                        				
                    </tr>
                    <tr>
                        <td> AUTHORIZED PERSON:</td>
                        <td>
                            <el-form-item prop="receiver"><el-input v-model="submitForm.receiver"></el-input></el-form-item>
                        </td>	
                    </tr>
                </table>
            </el-form>
            <div class="btnArea mt20 tac">
                <el-button type="primary" @click="queryAuth('submitForm')">Print</el-button>
            </div>
        </div>
        <!--授权确认页面弹窗-->
        <div>
            <ynet-authDialog ref="dialogTable"  @getAuthForm="getAuthForm"></ynet-authDialog>
        </div>
    </ynet-content>
</template>

<script>
    //import systemAdd from './components/systemAdd';
    //import systemEdit from './components/systemEdit';
	export default {
		name:'requestPin',
		components:{
          //systemEdit,
          //systemAdd
		},
		data(){
            return { 
                main:true,turnPageTotalNum:'',dialogTableVisible:false,
                isAdd:false,
                isEdit:false,
                systemSetList:[],//从后台查询到系统参数集合
                rules:{
                    accNo:[
                        {required:true,message:'required',trigger:'blur'},
                    ],
                    receiver:[
                        {required:true,message:'required',trigger:'blur'},
                    ]
                },
                isResult:false,
                needAuth:'',
                authType:'', 
                editData:{},
                submitForm:{
                    bsnCode:'IM0405',actionType:'0',accStt:'',receiver:''
                },
                authForm: { authUserNo: '', password: '',randomField:''},//100004   617100
                queryForm:{
                    accNo:'6226097805220050',bsnCode:'IM0405',currentPage:'1',turnPageShowNum:'10'
                },
                tableDate:[],

            }   
        },
		methods:{ 
            addRequest(){
                //this.submitForm=$.extend(this.submitForm,this.resultForm)
                console.log("submitForm:"+JSON.stringify(this.submitForm))
                this.$tools.request(this,"IM0305Action.do",this.submitForm).then(data=>{
                    console.log("data:"+JSON.stringify(data))
                    if(data.body.errorCode==0){
                        if(this.needAuth==1 && this.authType==2){
                            this.$message({
								type:'success',
								message:'Waiting for Authorized',
							})
                        }else if(this.needAuth==1 && this.authType==1){
                            if(data.body.authStatus==1){
                                this.$message.error({
                                     message:'Authorship No. or password wrong ,please resume load',
                                    showClose:true,
                                })
                            }else{
                                this.$message({
                                    type:'success',
                                    message:'Add Success',
                                    showClose:true,
                                })
                            }
                        }else{
                            this.$message({
                                type:'success',
                                message:'Add Success',
                                showClose:true,
                            })
                        }
                        
                    }else{
                        this.$alert("System Error Try again", "warning",  {
                            confirmButtonText: 'Confirm',
                            callback: action => {
                            }
                        }); 
                    }
                })
            },
            resetForm(formName){
                    this.$refs[formName].resetFields();
            },
            getAuthForm(val){
                //获取授权数据
                this.authForm=val;
                console.log("val:"+JSON.stringify(val))
                this.addForm=$.extend(this.addForm,this.authForm)
                this.typhoonAdd()  //自己页面提交给后台的.do方法
            },
            queryAuth(formName){//查询授权模式
                //this.$refs[formName].validate((valid)=>{
                    //if(valid){
                        let body={};body.bsnCode="IM0405";body.version="IM0405",
                        this.$tools.request(this,"IM010001Action.do",body).then(data=>{
                            if(data.body.errorCode==0){
                                if(data.body.needAuth==0){//无需授权
                                    this.addRequest()
                                }else if(data.body.needAuth==1 && data.body.authType==1){
                                    this.needAuth=1;
                                    this.authType=1;
                                    this.$refs["dialogTable"].show()
                                            // this.dialogTableVisible=true;
                                }else if( data.body.needAuth==1 && data.body.authType==2 ){
                                    this.needAuth=1;
                                    this.authType=2;
                                    this.addRequest()
                                }else{
                                    this.$alert('Authorization Type Error', {
                                        confirmButtonText: 'Confirm',
                                        callback: action => {
                                        }
                                    });
                                }
                            }else{
                                this.$alert("System Error Try again", "warning",{
                                    confirmButtonText: 'Confirm',
                                    callback: action => {
                                    }
                                });
                            }
                        })   
                   // }
                //})
                
			},
            queryChange(){
                this.$tools.request(this,"IM0305QueryAction.do",this.queryForm).then(data=>{
                   console.log("data:"+JSON.stringify(data))
                   if(data.body.errorCode==0){
                       if(data.body.requestPin.length==0){
                           console.log("no data")
                       }else{
                        this.submitForm=$.extend(this.submitForm,data.body.requestPin[0])
                        if(this.submitForm.accStt==2){
                            this.$alert("this account is closed","warning",{
                                confirmButtonText:'Confirm'
                            })
                        }
                       }
                        
                   }else{
                       this.$alert("System Error Try again", "warning",{
                            confirmButtonText: 'Confirm',
                            callback: action => {
                            }
                        })
                   }
               })
            },
            query(val){//查询频率控制
                //console.log("val:"+JSON.stringify(val))
                this.queryForm.currentPage=1
                console.log("queryForm:"+JSON.stringify(this.queryForm))
                this.queryChange()
            },
		}
	}
</script>